package com.dev.microserviceorder.controller;

import com.dev.microserviceorder.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : fujc-dev@qq.com
 * @motto : talk is cheap, show me the code. salute the future!
 */

@Controller
@RequestMapping("/home")
public class HomeController {

    @RequestMapping("/index")
    public Map<String, Object> getIndex() {
        Map<String, Object> container = new HashMap<>();
        container.put("code", 1);
        return container;
    }

    @RequestMapping("/balance/{name}")
    public String getBalance(@PathVariable("name") String name) {
        return "Hello," + name;
    }

    @RequestMapping("/projects")
    public Map<String, Object> getProjects() {
        Map<String, Object> container = new HashMap<>();
        container.put("code", 1);
        return container;
    }

    /**
     * spring mvc通过路径模板变量{变量名}这种方式，对URL带有参数的情况进行支持
     *
     * @param id
     * @param name
     * @param sex
     * @return
     */
    @RequestMapping("/user/{id}/{name}/{sex}")
    public User findUserById(@PathVariable Integer id, @PathVariable String name, @PathVariable String sex) {
        User user = new User();
        user.setId(id);
        user.setName(name);
        user.setSex(sex);
        return user;
    }
}
